﻿using System;
using System.Collections.Generic;
using System.Text;
using DepInnerTask.Common.Interface;
using DepInnerTask.Common.Entity;
using IBatisNet.DataMapper;
using Common.Service;
using System.Collections;
using Common.Logging;
using DepInner;
namespace DepInnerTask.Logic
{
    class DepInnerTaskLogic:IDepInnerTask
    {
        public IList GetList(string where, int start, int limit, out int count)
        {
            Hashtable table = new Hashtable();
            table.Add("taskid", "05041162c187f3a8e84ba5df1f54be");
            IList list = DataHelper.Instance().GetList("TaskLogic_GetList", table, start, limit);
            count = list.Count;

            return list;
        }
        public IList GetList(string where)
        {
            Hashtable table = new Hashtable();
            table.Add("INNER_TASK_ID ", where);
            IList list = DataHelper.Instance().GetList("DepInnerTask_GetListByID", table);
            return list;
        }
        public DepInnerTaskEntity Get(string taskId)
        {
            return DataHelper.Instance().Get<DepInnerTaskEntity>("DepInnerTask_GetList", taskId);
        }

        public void Insert(DepInnerTaskEntity entity)
        {
            DataHelper.Instance().Insert("InsertDepInnerTask", entity);
        }
        /// <summary>
        /// 事务操作
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="taskentity"></param>
        /// <param name="boxentity"></param>
        public void Insert(DepInnerTaskEntity entity, MessageQueueEntity taskentity, TInBoxReadEntity boxentity)
        {
            ISqlMapSession se = DataHelper.Instance().BeginTransaction("", "");
            try
            {
                 DataHelper.Instance().Insert("InsertDepInnerTask", entity);
                 DataHelper.Instance().Insert("InsertMessageQueue", taskentity);
                 DataHelper.Instance().Insert("InsertInBoxRead", boxentity);
                 se.CommitTransaction();
            }
            catch (Exception)
            {
                se.RollBackTransaction();
                throw;
            }
        }
        public void Update(DepInnerTaskEntity entity,string flag)
        {
            if (flag == "1")//关闭工单
            {
                DataHelper.Instance().Update("UpdateDepInnerTaskByID", entity);
            }
            else if (flag == "2")//新增处理人
            {
                DataHelper.Instance().Update("UpdateDepInnerTaskByInnerID", entity);
            }
        }

        public bool Exists(string taskId)
        {
            throw new NotImplementedException();
        }

        public void Delete(string taskId)
        {
            DataHelper.Instance().Delete("TaskLogic_Delete", taskId);
        }

    }
}
